package com.wxzz.elearing.user.api.admin;

import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.user.dto.EnterpriseApplyDto;
import com.wxzz.elearing.user.dto.FailEnterpriseApplyDto;
import com.wxzz.elearing.user.dto.PassEnterpriseApplyDto;
import com.wxzz.elearing.user.entity.AdminUser;
import com.wxzz.elearing.user.entity.EnterpriseApply;
import com.wxzz.elearing.user.service.IEnterpriseApplyService;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/enterprise-apply")
@Api(tags = "企业入驻申请接口(总后台)")
public class EnterpriseApplyController {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Autowired
    private IEnterpriseApplyService enterpriseApplyService;

    @ApiOperation(value = "企业入驻申请列表(总后台)", notes = "企业入驻申请列表(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "listEnterpriseApply", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<EnterpriseApply>> listEnterpriseApply(@RequestBody EnterpriseApplyDto enterpriseApplyDto) {
        return enterpriseApplyService.listEnterpriseApply(enterpriseApplyDto);
    }

    @ApiOperation(value = "企业审核通过(总后台)", notes = "企业审核通过(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "passEnterpriseApply", method = RequestMethod.POST)
    public ReturnVO<Long> passEnterpriseApply(@RequestHeader String token,@RequestBody PassEnterpriseApplyDto passEnterpriseApplyDto) {
        AdminUser adminUser = JSONObject.parseObject(redisTemplate.opsForValue().get(token), AdminUser.class);
        return enterpriseApplyService.passEnterpriseApply(adminUser,passEnterpriseApplyDto);
    }

    @ApiOperation(value = "企业审核失败(总后台)", notes = "企业审核失败(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "failEnterpriseApply", method = RequestMethod.POST)
    public ReturnVO failEnterpriseApply(@RequestHeader String token,@RequestBody FailEnterpriseApplyDto failEnterpriseApplyDto) {
        AdminUser adminUser = JSONObject.parseObject(redisTemplate.opsForValue().get(token), AdminUser.class);
        return enterpriseApplyService.failEnterpriseApply(adminUser,failEnterpriseApplyDto);
    }


}
